/***************************************************************
*  Copyright (c) 2007 by GroupMe! Team (www.groupme.net)
*  All rights reserved
*
*  This file is part of the GroupMe! Project. You can utilize
*  software of the GroupMe! project under the terms of the 
*  GNU Lesser General Public License as published by the
*  Free Software Foundation in version 2.1.
* 
*  The GNU Lesser General Public License can be found at:
*  http://www.gnu.org/licenses/lgpl.html
*
*  This copyright notice MUST APPEAR in all copies of the file!
***************************************************************/
package net.groupme.export.rdf;

import java.net.URI;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.groupme.exceptions.UserNotExistingException;
import net.groupme.model.ObjectFactory;

/**
 * This class provides the relation between a tag and the user/group/resource triple.
 * Additional informations are the creation date and the importance. This class is
 * used to stored these informations.
 *
 * @author Daniel Plappert
 * @version 0.1
 */
public class TaggingContext {
    
    /* Set default values for all attributes */
    private URI    group = null;
    private URI    resource = null;
    private URI    tag = null;
    private URI    user = null;
    private Date   creationDate = null;
    private int    importance = 0;
    
    
    /** Creates a new instance of TaggingContext */
    public TaggingContext() {}
    
    
    /**
     * Adds a new group and creates an URI. 
     *
     * @param int GroupID
     */
    public void setGroup(int groupId) {
    	if(groupId > 0){
    		this.group = ObjectFactory.getGroup(""+groupId).getURI();
    	}

    }
    
    
    /**
     * Returns the group´s URI
     *
     * @return URI URI of the group
     */
    public URI getGroup() {
        return group;
    }
    
    
    /**
     * Adds a new resource and creates an URI.
     *
     * @param int ID of the Resource
     */
    public void setResource(int resourceId) {
        this.resource = ObjectFactory.getResource(""+resourceId).getURI();
    }
    
    
    /**
     * Returns the uri of the resource.
     *
     * @return URI URI of the resource
     */
    public URI getResource() {
        return resource;
    }
    
    
    /**
     * Adds a new user and creates an URI.
     *
     * @param int ID of the user
     */
    public void setUser(int userId) {
        try {
			this.user =  ObjectFactory.getUser(userId).getURI();
		} catch (UserNotExistingException e) {
			e.printStackTrace();
			this.user = null;
		}
    }
    
    
    /**
     * Returns the uri of the user
     *
     * @return URI the user´s URI
     */
    public URI getUser() {
        return user;
    }
    
    
    /**
     * Sets the creation date of the relation context. The date will be
     * converted into an Date-Object.
     * 
     * @param String
     */
    public void setCreationDate(String stringDate) {
        
        SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
        try {
            creationDate = dateFormat.parse(stringDate);
        } catch (ParseException ex) {
            creationDate = null;
            ex.printStackTrace();
        }
        
    }
    
    
    /**
     * Sets the creation date of the relation context.
     *
     * @param Date
     */
    public void setCreationDate(Date date) {
        this.creationDate = date;
    }
    
    
    /**
     * Returns the creation date of the relation.
     *
     * @return Date
     */
    public Date getCreationDate() {
        return creationDate;
    }
    
    
    /**
     * Sets the importance. The string will be converted into an int-Value.
     *
     * @param String
     */
    public void setImportance(String importance) {
        this.importance = Integer.parseInt(importance);
    }
    
    
    /**
     * Sets the importance.
     *
     * @param int
     */
    public void setImportance(int importance) {
        this.importance = importance;
    }
    
    
    /**
     * Returns the importance.
     *
     * @return int
     */
    public int getImportance() {
        return importance;
    }


	/**
	 * This method returns the tag of a TaggingContext object.
	 * @return the tag
	 */
	public URI getTag() {
		return tag;
	}


	/**
	 * This method sets the tag of a TaggingContext object.
	 * @param tag the tag to set
	 */
	public void setTag(int tagId) {
		this.tag = ObjectFactory.getTagById(""+tagId).getURI();
	}
}
